<?php
	require_once('../utils/query.php');
	
	$cardname = $_GET["cardname"];
	$cardname = stripslashes($cardname);
	$cardtype = $_GET["cardtype"];
?>

<!--<ul class="cards">-->
<ul>
	<?php
		$filter = '';
		if ($cardname=="Card name")
			$cardname = "";
		if ($type_filter)
			$filter = $filter . " AND type = " . mysql_real_escape_string($type_filter);
		if ($sort_by)
			$filter = $filter . " ORDER BY " . mysql_real_escape_string($sort_by);
		if ($range)
			$filter = $filter . " LIMIT " . mysql_real_escape_string($range);
		
		$store_result = execute_query_unsafe("SELECT cardid, storeitemid FROM StoreItemCards");
		
		while ($row1 = mysql_fetch_array($store_result))
		{
			if($cardtype=="0")
				$cards_result = execute_query("SELECT full_id, name, card_img, type FROM cards_lu WHERE front is null AND full_id='%s' AND name LIKE '%s'", $row1[0], "%" . $cardname . "%");
			else
				$cards_result = execute_query("SELECT full_id, name, card_img, type FROM cards_lu WHERE front is null AND type='%s'AND full_id='%s' AND name LIKE '%s'", $cardtype, $row1[0], "%" . $cardname . "%");

			$row = mysql_fetch_array($cards_result);
			
			if($row)
			{
			$cardid = $row[0];
			$name = $row[1];
			$card_img = $row[2];
			$type = $row[3];
			
			$color = "#ffffff";
			if ($type == 1)
				$color = "#dc3122";
			else if ($type == 2)
				$color = "#ddd327";
			else if ($type == 3)
				$color = "#0145f3";
			else if ($type == 10)
				$color = "#653b67";
				
			
			
			$storeItemInfo = execute_query("SELECT name, description, price FROM StoreItem WHERE storeitemid='%s'", $row1[1]); 
			$storeItemInfo = mysql_fetch_array($storeItemInfo);
			
			$name = $storeItemInfo[0];
			$desc = $storeItemInfo[1];
			$price = $storeItemInfo[2];


			if(strlen($name) > 16)
			$showname = substr ($name,0,16) . "...";
			else
			$showname = $name;

	?>
			
			<li class="card" id="<?php echo($cardid); ?>">
				<div class="cardImg">
					<img src="../../../card_imgs/<?php echo($card_img); ?>">
				</div>
				<!--<div class="cardDesc" style="background:<?php echo($color); ?>;">-->
				<div class="cardDesc">
					<?php echo($showname); ?>
				</div>
				<div class="cardPrice" align="center">
					<?php echo($price . "pts"); ?>
				</div>
				<div class="description">
					<?php echo($desc); ?>
				</div>
			</li>
	<?php
			}
		}
	?>
</ul>
